package com.czn.shopdemo.config;

import com.czn.shopdemo.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author Zenan Chen
 * @date 2023/4/4 10:56
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册LoginInterceptor拦截器
        registry.addInterceptor(loginInterceptor())
                .excludePathPatterns("/user/login")                //添加不拦截的请求路径
                .excludePathPatterns("/payment/alipay")
                .excludePathPatterns("/payment/result")
        ;
    }

    @Bean
    public LoginInterceptor loginInterceptor() {
        return new LoginInterceptor();
    }
}
